home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / util1 / yk211src.lha / Yak_2.11_Src / Prefs / GadTools / Mousecycling_window.c < prev    next >
C/C++ Source or Header  |  1995-11-16  |  17KB  |  523 lines

  1.  
  2. /*
  3.  *  Source machine generated by GadToolsBox V2.0b
  4.  *  which is (c) Copyright 1991-1993 Jaba Development
  5.  *
  6.  *  GUI Designed by : Martin W Scott and Gaël Marziou
  7.  */
  8.  
  9.  
  10. #define __USE_SYSBASE
  11.  
  12. #include <exec/execbase.h>
  13. #include <exec/memory.h>
  14. #include <exec/types.h>
  15. #include <intuition/intuition.h>
  16. #include <intuition/classes.h>
  17. #include <intuition/classusr.h>
  18. #include <intuition/imageclass.h>
  19. #include <intuition/gadgetclass.h>
  20. #include <libraries/gadtools.h>
  21. #include <workbench/workbench.h>
  22. #include <proto/exec.h>
  23. #include <proto/dos.h>
  24. #include <proto/intuition.h>
  25. #include <proto/gadtools.h>
  26. #include <proto/wb.h>
  27. #include <string.h>
  28. #include <stdlib.h>
  29.  
  30. #include "code.h"
  31. #include "version.h"
  32. #include "yak.h"
  33. #include "hotkey_types.h"
  34. #include "MouseCycling_Window.h"
  35. #include "KeyDef_Window.h"
  36. #include "gui.h"
  37. #include "Handlers.h"
  38. #include "Requesters.h"
  39.  
  40.  
  41. #define CATCOMP_NUMBERS
  42. #include "yak_locale_strings.h"
  43.  
  44.  
  45. IMPORT LONG (*HandleIDCMP)(VOID);
  46.  
  47. struct Window         *MouseCyclingWnd = NULL;
  48. struct Gadget         *MouseCyclingGList = NULL;
  49. struct Gadget         *MouseCyclingGadgets[MouseCycling_CNT];
  50. UWORD                  MouseCyclingWidth  = 532;
  51. UWORD                  MouseCyclingHeight = 185;
  52. UBYTE                 *MouseCyclingWdt = NULL;
  53. BOOL                   MouseCyclingWdi = FALSE;
  54.  
  55. struct AppWindow      *MouseCyclingAppWin;         /* AppWindow pointer */
  56. IMPORT struct MsgPort *AppMsgPort;
  57.  
  58. UBYTE *Click1Labels[4];
  59.  
  60. /* Online help system */
  61. IMPORT void ShowYakHelp(char *, char *);
  62. IMPORT void CloseYakHelp(void);
  63. IMPORT char *PrefsHelp;
  64.  
  65.  
  66. struct IntuiText MouseCyclingIText[] = {
  67.     2, 0, JAM1,69, 9, NULL, NULL, NULL,
  68.     2, 0, JAM1,62, 76, NULL, NULL, NULL,
  69.     2, 0, JAM1,63, 131, NULL, NULL, NULL };
  70.  
  71. #define MouseCycling_TNUM 3
  72.  
  73. UWORD MouseCyclingGTypes[] = {
  74.     CHECKBOX_KIND,
  75.     CHECKBOX_KIND,
  76.     CHECKBOX_KIND,
  77.     CHECKBOX_KIND,
  78.     CHECKBOX_KIND,
  79.     CYCLE_KIND,
  80.     CHECKBOX_KIND,
  81.     STRING_KIND,
  82.     STRING_KIND,
  83.     STRING_KIND,
  84.     BUTTON_KIND,
  85.     BUTTON_KIND,
  86.     BUTTON_KIND,
  87.     CYCLE_KIND,
  88.     CYCLE_KIND,
  89.     BUTTON_KIND
  90. };
  91.  
  92. struct NewGadget MouseCyclingNGad[] = {
  93.       6,  15,  26, 13, NULL, NULL, GD_WindowToFrontActive, PLACETEXT_RIGHT, NULL, STATE_ACTIVE_STRING,
  94.       6,  75,  26, 13, NULL, NULL, GD_WindowToBackActive,  PLACETEXT_RIGHT, NULL, STATE_ACTIVE_STRING,
  95.       6, 135,  26, 13, NULL, NULL, GD_ScreenCyclingActive, PLACETEXT_RIGHT, NULL, STATE_ACTIVE_STRING,
  96.       6,  29,  26, 13, NULL, NULL, GD_ScreenToFront_Check, PLACETEXT_RIGHT, NULL, ScreenToFront_ACT,
  97.       6,  89,  26, 13, NULL, NULL, GD_ScreenToBack_Check,  PLACETEXT_RIGHT, NULL, ScreenToBack_ACT,
  98.       6,  43, 146, 13, NULL, NULL, GD_WindowToFrontClicks, 0, NULL, NULL,
  99.     180,  15,  26, 13, NULL, NULL, GD_ExcludeWbWindow,     PLACETEXT_RIGHT, NULL, EXCLUDE_WB_WINDOW,
  100.     325,  29, 200, 13, NULL, NULL, GD_WindowToFrontPattern,PLACETEXT_LEFT, NULL, INCLUDE_SCREENS,
  101.     325,  89, 200, 13, NULL, NULL, GD_WindowToBackPattern, PLACETEXT_LEFT, NULL, INCLUDE_SCREENS,
  102.     325, 135, 200, 13, NULL, NULL, GD_ScreenCyclingPattern,PLACETEXT_LEFT, NULL, INCLUDE_SCREENS,
  103.     180, 149, 140, 13, NULL, NULL, GD_HotkeyScreenCycling, PLACETEXT_IN, NULL, DEFINITION_STRING,
  104.     180, 103, 140, 13, NULL, NULL, GD_HotkeyWindowToBack,  PLACETEXT_IN, NULL, DEFINITION_STRING,
  105.     180,  43, 140, 13, NULL, NULL, GD_HotkeyWindowToFront, PLACETEXT_IN, NULL, DEFINITION_STRING,
  106.       6, 103, 146, 13, NULL, NULL, GD_WindowToBackClicks,  0, NULL, NULL,
  107.       6, 149, 146, 13, NULL, NULL, GD_ScreenCyclingClicks, 0, NULL, NULL,
  108.     215, 169, 100, 13, NULL, NULL, GD_Return5,             PLACETEXT_IN   ,NULL ,OK_STRING
  109. };
  110.  
  111. ULONG MouseCyclingGTags[] = {
  112.     (GTCB_Scaled),TRUE,(TAG_DONE),
  113.     (GTCB_Scaled),TRUE,(TAG_DONE),
  114.     (GTCB_Scaled),TRUE,(TAG_DONE),
  115.     (GTCB_Scaled),TRUE,(TAG_DONE),
  116.     (GTCB_Scaled),TRUE,(TAG_DONE),
  117.     (GTCY_Labels), (ULONG)&Click1Labels[ 0 ],  (TAG_DONE),
  118.     (GTCB_Scaled),TRUE,(TAG_DONE),
  119.     (GTST_MaxChars), 256, (TAG_DONE),
  120.     (GTST_MaxChars), 256, (TAG_DONE),
  121.     (GTST_MaxChars), 256, (TAG_DONE),
  122.     (TAG_DONE),
  123.     (TAG_DONE),
  124.     (TAG_DONE),
  125.     (GTCY_Labels), (ULONG)&Click1Labels[ 0 ],  (TAG_DONE),
  126.     (GTCY_Labels), (ULONG)&Click1Labels[ 0 ],  (TAG_DONE),
  127.     (TAG_DONE)
  128. };
  129.  
  130.  
  131.  
  132.  
  133. VOID
  134. InitClick1Labels(VOID)
  135. {
  136.     Click1Labels[0] = getString(SIMPLE_CLICK_STRING);
  137.     Click1Labels[1] = getString(DOUBLE_CLICK_STRING);
  138.     Click1Labels[2] = getString(TRIPLE_CLICK_STRING);
  139.     Click1Labels[3] = NULL;
  140. }
  141.  
  142.  
  143. VOID
  144. InitMouseCyclingITexts(VOID)
  145. {
  146.    MouseCyclingIText[0].IText = getString(WINDOW_TO_FRONT);
  147.    MouseCyclingIText[1].IText = getString(WINDOW_TO_BACK);
  148.    MouseCyclingIText[2].IText = getString(SCREENS_CYCLING);
  149. }
  150.  
  151. void 
  152. MouseCyclingRender( void )
  153. {
  154.     struct IntuiText    it;
  155.     UWORD           cnt;
  156.     UWORD Y, Width, Height;
  157.  
  158.     ComputeFont( MouseCyclingWidth, MouseCyclingHeight );
  159.  
  160.     Width = ComputeX( MouseCyclingWidth );
  161.     Y = 0;
  162.     Height = ComputeY(60);
  163.     MouseCyclingIText[0].TopEdge = Y+3;
  164.  
  165.     DrawThinBevelBox(Scr, MouseCyclingWnd->RPort, OffX,
  166.                      OffY+Y,
  167.                      Width,
  168.                      Height,
  169.                      FALSE );
  170.  
  171.     Y = Height;
  172.     Height = ComputeY(120) - Y;
  173.     MouseCyclingIText[1].TopEdge = Y+3;
  174.  
  175.     DrawThinBevelBox(Scr, MouseCyclingWnd->RPort, OffX,
  176.                      OffY+Y,
  177.                      Width,
  178.                      Height,
  179.                      FALSE );
  180.  
  181.     Y += Height;
  182.     Height = ComputeY(166) - Y;
  183.     MouseCyclingIText[2].TopEdge = Y+3;
  184.  
  185.     DrawThinBevelBox(Scr, MouseCyclingWnd->RPort, OffX,
  186.                      OffY+Y,
  187.                      Width,
  188.                      Height,
  189.                      FALSE );
  190.  
  191.     Y += Height;
  192.     Height = ComputeY(MouseCyclingHeight) - Y;
  193.     DrawThinBevelBox(Scr, MouseCyclingWnd->RPort, OffX,
  194.                      OffY+Y,
  195.                      Width,
  196.                      Height,
  197.                      FALSE );
  198.  
  199.     for ( cnt = 0; cnt < MouseCycling_TNUM; cnt++ ) {
  200.         CopyMem(( char * )&MouseCyclingIText[ cnt ], ( char * )&it, (long)sizeof( struct IntuiText ));
  201.         it.ITextFont = Font;
  202.         it.LeftEdge  = 5;
  203.         PrintIText( MouseCyclingWnd->RPort, &it, OffX, OffY );
  204.     }
  205. }
  206.  
  207. int 
  208. OpenMouseCyclingWindow(VOID)
  209. {
  210.     struct NewGadget   ng;
  211.     struct Gadget     *g;
  212.     UWORD              lc, tc;
  213.     WORD               wleft=WindowLeft, wtop=WindowTop;
  214.     UWORD              ww, wh;
  215.  
  216.     ComputeFont( MouseCyclingWidth, MouseCyclingHeight );
  217.  
  218.     ww = OffX + ComputeX( MouseCyclingWidth ) + Scr->WBorRight;
  219.     wh = OffY + ComputeY( MouseCyclingHeight ) + Scr->WBorBottom;
  220.  
  221.     SetUpWindowCoordinates(ww, wh, &wleft, &wtop);
  222.  
  223.     if ( ! ( g = CreateContext( &MouseCyclingGList )))
  224.         return( 1L );
  225.  
  226.     for( lc = 0, tc = 0; lc < MouseCycling_CNT; lc++ ) {
  227.  
  228.         CopyMem((char * )&MouseCyclingNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  229.  
  230.         ng.ng_VisualInfo = VisualInfo;
  231.         ng.ng_TextAttr   = Font;
  232.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  233.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  234.         ng.ng_Width      = ComputeX( ng.ng_Width );
  235.         ng.ng_Height     = ComputeY( ng.ng_Height);
  236.  
  237.         MouseCyclingGadgets[ lc ] = g = CreateGadgetA((ULONG)MouseCyclingGTypes[ lc ], g, &ng, ( struct TagItem * )&MouseCyclingGTags[ tc ] );
  238.  
  239.         while( MouseCyclingGTags[ tc ] ) tc += 2;
  240.         tc++;
  241.  
  242.         if ( NOT g )
  243.             return( 2L );
  244.     }
  245.  
  246.     if ( ! ( MouseCyclingWnd = OpenWindowTags( NULL,
  247.                 WA_Left,    wleft,
  248.                 WA_Top,     wtop,
  249.                 WA_Width,   ww,
  250.                 WA_Height,  wh,
  251.                 WA_IDCMP,   CHECKBOXIDCMP|CYCLEIDCMP|STRINGIDCMP|BUTTONIDCMP|IDCMP_REFRESHWINDOW|IDCMP_RAWKEY,
  252.                 WA_Flags,   WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_SMART_REFRESH,
  253.                 WA_Gadgets, MouseCyclingGList,
  254.                 WA_Title,   MouseCyclingWdt,
  255.                 WA_ScreenTitle, getString(COPYRIGHT_STRING),
  256.                                 WA_PubScreenName,PubScreenName,
  257.                 TAG_DONE )))
  258.     return( 4L );
  259.  
  260.     MouseCyclingAppWin = AddAppWindowA(0, 0, MouseCyclingWnd, AppMsgPort, NULL);
  261.  
  262.     GT_RefreshWindow( MouseCyclingWnd, NULL );
  263.  
  264.     MouseCyclingRender();
  265.  
  266.     return( 0L );
  267. }
  268.  
  269. void 
  270. CloseMouseCyclingWindow( void )
  271. {
  272.     CloseOneWindow (MouseCyclingWnd, NULL, MouseCyclingGList, MouseCyclingAppWin);
  273.     MouseCyclingWnd = NULL;
  274. }
  275.  
  276.  
  277.  
  278.  
  279. static void
  280. InitMouseCyclingGad(UWORD num, LONG tagtype, LONG tagvalue, UWORD state)
  281. {
  282.     InitWindowGadget(num, tagtype, tagvalue, MCYCLING_WINDOW);
  283.     InitWindowGadget(num, GA_Disabled, !state, MCYCLING_WINDOW);
  284. }
  285.  
  286. static void
  287. InitWindowToFrontGads(VOID)
  288. {
  289.     UWORD state;
  290.  
  291.     state = Window_To_Front.State;
  292.     InitMouseCyclingGad(GDX_WindowToFrontActive , GTCB_Checked, state, TRUE);
  293.     InitMouseCyclingGad(GDX_WindowToFrontClicks , GTCY_Active , Window_To_Front.RequiredClicks-1, state);
  294.     InitMouseCyclingGad(GDX_ScreenToFront_Check , GTCB_Checked, Window_To_Front.Options & Opt_ScreenToFront, state);
  295.     InitMouseCyclingGad(GDX_ExcludeWbWindow     , GTCB_Checked, Window_To_Front.Options & Opt_ExcludeWbWindow, state);
  296.     InitMouseCyclingGad(GDX_WindowToFrontPattern, GTST_String , (LONG)Window_To_Front.ScreenPatternData.patstr, state);
  297.     InitWindowGadget(GDX_HotkeyWindowToFront , GA_Disabled , !state, MCYCLING_WINDOW);
  298. }
  299.  
  300. static void
  301. InitWindowToBackGads(VOID)
  302. {
  303.     UWORD state;
  304.  
  305.     state = Window_To_Back.State;
  306.     InitMouseCyclingGad(GDX_WindowToBackActive , GTCB_Checked, state, TRUE);
  307.     InitMouseCyclingGad(GDX_WindowToBackClicks , GTCY_Active , Window_To_Back.RequiredClicks-1, state);
  308.     InitMouseCyclingGad(GDX_ScreenToBack_Check , GTCB_Checked, Window_To_Back.Options & Opt_ScreenToBack, state);
  309.     InitMouseCyclingGad(GDX_WindowToBackPattern, GTST_String , (LONG)Window_To_Back.ScreenPatternData.patstr, state);
  310.     InitWindowGadget(GDX_HotkeyWindowToBack , GA_Disabled , !state, MCYCLING_WINDOW);
  311. }
  312.  
  313. static void
  314. InitScreenCyclingGads(VOID)
  315. {
  316.     UWORD state;
  317.  
  318.     state = ScreenCycling.State;
  319.     InitMouseCyclingGad(GDX_ScreenCyclingActive , GTCB_Checked, state, TRUE);
  320.     InitMouseCyclingGad(GDX_ScreenCyclingClicks , GTCY_Active , ScreenCycling.RequiredClicks-1, state);
  321.     InitMouseCyclingGad(GDX_ScreenCyclingPattern, GTST_String , (LONG)ScreenCycling.ScreenPatternData.patstr, state);
  322.     InitWindowGadget(GDX_HotkeyScreenCycling , GA_Disabled , !state, MCYCLING_WINDOW);
  323. }
  324.  
  325. static void
  326. InitMouseCyclingGadgets(VOID)
  327. {
  328.     /* Window To Front gadgets */
  329.     InitWindowToFrontGads();
  330.  
  331.     /* Window To Back gadgets */
  332.     InitWindowToBackGads();
  333.  
  334.     /* Screen Cycling gadgets */
  335.     InitScreenCyclingGads();
  336. }
  337.  
  338.  
  339. /* handle Blank window events */
  340. LONG
  341. HandleMouseCyclingIDCMP(VOID)
  342. {
  343.     struct IntuiMessage *msg;
  344.     struct Gadget   *gadget;
  345.     ULONG           class;
  346.     UWORD           code;
  347.     BOOL            close=FALSE;
  348.     LONG            ret=RET_OKAY;
  349.  
  350.     while (!close && (msg=GT_GetIMsg(MouseCyclingWnd->UserPort)))
  351.     {
  352.         class = msg->Class;
  353.         code  = msg->Code;
  354.         gadget = (struct Gadget *)msg->IAddress;
  355.         GT_ReplyIMsg(msg);
  356.  
  357.         switch (class)
  358.         {
  359.           case REFRESHWINDOW:
  360.             GT_BeginRefresh(MouseCyclingWnd);
  361.             GT_EndRefresh(MouseCyclingWnd, TRUE);
  362.             break;
  363.  
  364.           case GADGETUP:
  365.           case GADGETDOWN:
  366.             switch (gadget->GadgetID)
  367.             {
  368.               case GD_Return5:
  369.                 CloseMouseCyclingWindow();
  370.                 if (!ShowWindowID(ROOT_WINDOW))
  371.                     ret = RET_QUIT;
  372.                 close = TRUE;
  373.                 break;
  374.  
  375.                 /*******************/
  376.                 /* Window To Front */
  377.                 /*    Gadgets      */
  378.                 /*******************/
  379.  
  380.               case GD_WindowToFrontActive:
  381.                 Window_To_Front.State ^= YKHK_ACTIVE;
  382.                 InitWindowToFrontGads();
  383.                 break;
  384.                             
  385.               case GD_ScreenToFront_Check:
  386.                 Window_To_Front.Options ^= Opt_ScreenToFront;
  387.                 break;
  388.  
  389.               case GD_ExcludeWbWindow:
  390.                 Window_To_Front.Options ^= Opt_ExcludeWbWindow;
  391.                 break;
  392.  
  393.               case GD_WindowToFrontClicks:
  394.                 Window_To_Front.RequiredClicks = code + 1;
  395.                 break;
  396.  
  397.               case GD_HotkeyWindowToFront:
  398.                 if (!SwitchToKeyDefWindow(MCYCLING_WINDOW,
  399.                                           &Window_To_Front,
  400.                                           getString(WINDOW_TO_FRONT)))
  401.                 {
  402.                     PostError(getString(Couldnt_open_other_window_ERR));
  403.                     ret = RET_QUIT;
  404.                 }
  405.                 close = TRUE;
  406.                 break;
  407.  
  408.  
  409.               case GD_WindowToFrontPattern:
  410.                 NewPattern(GDX_WindowToFrontPattern, &Window_To_Front.ScreenPatternData, gadget, MCYCLING_WINDOW);
  411.                 break;
  412.  
  413.                 /******************/
  414.                 /* Window To Back */
  415.                 /*    Gadgets     */
  416.                 /******************/
  417.  
  418.               case GD_WindowToBackActive:
  419.                 Window_To_Back.State ^= YKHK_ACTIVE;
  420.                 InitWindowToBackGads();
  421.                 break;
  422.                             
  423.               case GD_ScreenToBack_Check:
  424.                 Window_To_Back.Options ^= Opt_ScreenToBack;
  425.                 break;
  426.  
  427.               case GD_WindowToBackClicks:
  428.                 Window_To_Back.RequiredClicks = code + 1;
  429.                 break;
  430.  
  431.               case GD_HotkeyWindowToBack:
  432.                 if (!SwitchToKeyDefWindow(MCYCLING_WINDOW,
  433.                                           &Window_To_Back,
  434.                                           getString(WINDOW_TO_BACK)))
  435.                 {
  436.                     PostError(getString(Couldnt_open_other_window_ERR));
  437.                     ret = RET_QUIT;
  438.                 }
  439.                 close = TRUE;
  440.                 break;
  441.  
  442.               case GD_WindowToBackPattern:
  443.                 NewPattern(GDX_WindowToBackPattern, &Window_To_Back.ScreenPatternData, gadget, MCYCLING_WINDOW);
  444.                 break;
  445.  
  446.                 /******************/
  447.                 /* Screen Cycling */
  448.                 /*    Gadgets     */
  449.                 /******************/
  450.  
  451.               case GD_ScreenCyclingActive:
  452.                 ScreenCycling.State ^= YKHK_ACTIVE;
  453.                 InitScreenCyclingGads();
  454.                 break;
  455.                             
  456.               case GD_ScreenCyclingClicks:
  457.                 ScreenCycling.RequiredClicks = code + 1;
  458.                 break;
  459.  
  460.               case GD_HotkeyScreenCycling:
  461.                 if (!SwitchToKeyDefWindow(MCYCLING_WINDOW,
  462.                                           &ScreenCycling,
  463.                                           getString(SCREENS_CYCLING)))
  464.                 {
  465.                     PostError(getString(Couldnt_open_other_window_ERR));
  466.                     ret = RET_QUIT;
  467.                 }
  468.                 close = TRUE;
  469.                 break;
  470.                             
  471.               case GD_ScreenCyclingPattern:
  472.                 NewPattern(GDX_ScreenCyclingPattern, &ScreenCycling.ScreenPatternData, gadget, MCYCLING_WINDOW);
  473.                 break;
  474.  
  475.             }                   /* switch (gadget->GadgetID) */
  476.             break;
  477.  
  478.           case IDCMP_RAWKEY:
  479.                 /* Help key pressed */
  480.                 if (code == 95)
  481.                 {
  482.                     /* Display the node */
  483.                     ShowYakHelp(PrefsHelp, "MouseCycling");
  484.                 }
  485.                 break;
  486.         }                       /* switch (class) */
  487.     }                           /* while more messages */
  488.     return ret;
  489. }
  490.  
  491.  
  492. /* show our MouseCycling window */
  493. BOOL
  494. ShowMouseCyclingWindow(VOID)
  495. {
  496.     if (!MouseCyclingWdi)
  497.     {
  498.         MouseCyclingWdi = TRUE;
  499.  
  500.         MouseCyclingWdt = getString(MOUSECYCLING_STRING);
  501.         InitMouseCyclingITexts();
  502.         LocalizeNGadLabels (MouseCycling_CNT, MouseCyclingNGad);
  503.         InitClick1Labels ();
  504.     }
  505.  
  506.     if (!OpenMouseCyclingWindow()) /* like the name says... */
  507.     {
  508.         InitMouseCyclingGadgets();
  509.         wndsigflag = 1 << MouseCyclingWnd->UserPort->mp_SigBit;
  510.         curwin = MouseCyclingWnd;
  511.         curwinID = MCYCLING_WINDOW;
  512.         HandleIDCMP = HandleMouseCyclingIDCMP;
  513.         return TRUE;
  514.     }
  515.  
  516.     FreeGadgets(MouseCyclingGList);
  517.     CloseDownScreen();
  518.     curwin =  NULL;
  519.     wndsigflag = 0L;
  520.     return FALSE;
  521. }
  522.  
  523.